package com.dubbo.dubboclient.controller;

import com.dubbo.dubboclient.aervice.DubboService;
import com.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Controller
public class HomeController {

    @Autowired
    private DubboService dubboService ;

    @GetMapping(value = "/")
    public String login(){
        return "system/register";
    }

    @PostMapping(value = "/register")
    public String get(HttpServletRequest request , HttpServletResponse response,Model model ){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(username);
        userInfo.setPassword(password);
        userInfo.setCreateDate(new Date());

//        try {
            dubboService.register(userInfo);
//        } catch (MyExecption myExecption) {
//            model.addAttribute("msg",myExecption.getMessage());
//            return "system/register";
//        }

        return "system/login";

    }
}
